import ajax from 'assets/js/ajaxHelper.js'
import vm from './viewModel.js'

export default {
  MenusTypes(callback) {      // 菜谱分类
    var url = 'classify?id=0'
    ajax.BaiduGet(url, function(result){
      if (result.status){
        var datas = vm.convertMenusTypes(result.tngou)
        callback && callback(datas)
      } else {
        console.log('MenusTypes error!')
      }
    })
  },
  MenusList(id, callback){    // 菜谱列表
    var url = `list?id=${id}&page=1&rows=20`
    ajax.BaiduGet(url, function(result){
      if (result.status){
        var datas = vm.convertMenusList(result.tngou)
        callback && callback(datas)
      } else {
        console.log('MenusTypes error!')
      }
    })
  },
  MenusInfo(id, callback){    // 菜谱详情
    var url = `show?id=${id}`
    ajax.BaiduGet(url, function(result){
      var datas = vm.convertMenusInfo(result)
      callback && callback(datas)
    })
  },
  SearchMenus(name, callback){  // 菜谱名称
    var url = `name?name=${encodeURIComponent(name)}`
    ajax.BaiduGet(url, function(result){
      console.log(result)
      if (result.status){
        var datas = vm.convertMenusList(result.tngou)
        callback && callback(datas)
      } else {
        console.log('MenusTypes error!')
      }
    })
  }
}
